﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebPartPages;

namespace SPOnlineDevelopTool.Utilities
{
    public class SPHelper
    {
        /// <summary>
        /// 判断是否在编辑模式
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public static bool IsInEditMode(System.Web.UI.Page page)
        {

            switch (SPContext.Current.FormContext.FormMode)
            {
                case Microsoft.SharePoint.WebControls.SPControlMode.Display:
                    break;
                case Microsoft.SharePoint.WebControls.SPControlMode.Edit:
                case Microsoft.SharePoint.WebControls.SPControlMode.Invalid:
                case Microsoft.SharePoint.WebControls.SPControlMode.New:
                    return true;
                default:
                    break;
            }
            var wpm = WebPartManager.GetCurrentWebPartManager(page);
            if (wpm != null)
            {
                if (WebPartManager.DesignDisplayMode == wpm.DisplayMode)
                {
                    return true;
                }
            }
            return false;
        }

    }
}
